﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ForumsBrowser
{
    /// <summary>
    /// Interaction logic for Star.xaml
    /// </summary>
    public partial class Star : UserControl
    {
        public Star()
        {
            InitializeComponent();
        }

        void Star_Loaded(object sender, RoutedEventArgs e)
        {
            Polygon pg = new Polygon();
            pg.Fill = Achieved < Threshhold ? Brushes.Transparent : FillBrush;
            pg.Stroke = this.Edge;
            pg.Points = StarPointsGenerator.Generate(this.ActualHeight, 5);
            this.Content = pg;
        }

        public static readonly DependencyProperty ThreshholdProperty = DependencyProperty.Register(
            "Threshhold", typeof(int), typeof(Star));

        public static readonly DependencyProperty AchievedProperty = DependencyProperty.Register(
            "Achieved", typeof(int), typeof(Star));

        public static readonly DependencyProperty FillBrushProperty = DependencyProperty.Register(
            "FillBrush", typeof(Brush), typeof(Star), new PropertyMetadata(Brushes.Yellow));

        public static readonly DependencyProperty EdgeProperty = DependencyProperty.Register(
            "Edge", typeof(Brush), typeof(Star), new PropertyMetadata(Brushes.Black));

        public int Achieved
        {
            get { return (int)this.GetValue(AchievedProperty); }
            set { this.SetValue(AchievedProperty, value); }
        }

        public int Threshhold
        {
            get { return (int)this.GetValue(ThreshholdProperty); }
            set { this.SetValue(ThreshholdProperty, value); }
        }

        public Brush FillBrush
        {
            get { return (Brush)this.GetValue(FillBrushProperty); }
            set { this.SetValue(FillBrushProperty, value); }
        }

        public Brush Edge
        {
            get { return (Brush)this.GetValue(EdgeProperty); }
            set { this.SetValue(EdgeProperty, value); }
        }
    }
}
